package com.adminpcBo;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;



import javax.faces.component.html.HtmlDataTable;
import javax.faces.component.html.HtmlInputHidden;
import com.adminpcMod.*;
import com.adminpcDao.*;

public class UserBo implements java.io.Serializable{

	private  int identite;
	private  String nom_createUser;
	private  String prenom_createUser;
	private  String login_createUser;
	private  String password_createUser;
	private  String login_login;
	private  String password_login;
	private  String name_Computer;
	private  String ipadresse_Computer;
	private  String dns_Computer;
	private User updateuser;
	public long data;
	private List user;
	private List computer;
	public  static List<File> file;
	private HtmlInputHidden dataItemId = new HtmlInputHidden();
	private HtmlDataTable dataTable;
    private UserComputer dataItem;
	private UserDao userDAO = new UserDao();
	private FileDao fileBo = new FileDao();  
    private List<UserComputer> pers = new ArrayList<UserComputer>();
    private List<UserComputer> usercomput = new ArrayList<UserComputer>();

// Actions -----------------------------------------------------------------------------------    	
    
    //Constructeur    
    	public UserBo(){

		}
    
    	
    //test de ping
	    public String editDataItem() {
        String RetVal="";
	        // Get selected MyData item to be edited.
            UserComputer dataItem = (UserComputer) dataTable.getRowData();
	        // Store the ID of the data item in hidden input element.
	        RetVal = userDAO.editAction(dataItem.getUser().getIdentiUser());
	        System.out.println(RetVal);
	         if(RetVal.equals("PingNOk")){
	        	 return "Deconnexion"; 
	        }else{
	        	
	        	filelist(dataItem.getUser().getIdentiUser());
	        	return "userfile";
	        }
	    }
	  //-------------------------------  
	  public List<File> filelist(long ident){
		  file = fileBo.getUserFile(ident);
		  return file;
	  }
	 //-------------------------------  
	 //Update User
	    public String Update() {
	        // Get selected MyData item to be edited.
	    	UserComputer usercomput = (UserComputer) dataTable.getRowData();
	    
	    	usercomput.setEditable(true);
	        return "null";
	    }
	    
	    
	 //Save update User
		 public void Save() {   
		 UserComputer usercomput = (UserComputer) dataTable.getRowData();
	     userDAO.updateUser(usercomput);     	
	     usercomput.setEditable(false);
	     }
		 
		 
	 //Supprimer User
	    public void DeletDataItem() {
		        // Get selected MyData item to be edited.
	    	  //User dataItem = (User) dataTable.getRowData();
	    	  UserComputer dataItem = (UserComputer) dataTable.getRowData();
		     // Store the ID of the data item in hidden input element.
		      userDAO.deleteUser(dataItem.getUser().getIdentiUser());
		      pers.remove(dataTable.getRowIndex()); 
		    }
	    
	    
	//Check session de connexion
		public String CheckLoginBo (){
			String RetVal = userDAO.CheckLoginDAO(login_login, password_login);
			if (RetVal.equals("LoginOk")){
			pers = userDAO.getUserList();	
		}
		return(RetVal);
		}
		
		
	//Create New User
		public String createUserBo(){
		User user = (new User(nom_createUser,prenom_createUser,login_createUser,password_createUser));
		Computer computer = (new Computer(name_Computer,ipadresse_Computer,dns_Computer,user));
		pers.add(new UserComputer(user,computer));
		return (userDAO.createUserDao(nom_createUser,prenom_createUser,login_createUser,password_createUser,
				name_Computer,ipadresse_Computer,dns_Computer));
		}
		
		
// Getters -----------------------------------------------------------------------------------

	    public int getIdentite() {
			return identite;
		}

		public String getNom_createUser() {
			return nom_createUser;
		}
		
		public String getPrenom_createUser() {
			return prenom_createUser;
		}
	
		public String getLogin_createUser() {
			return login_createUser;
		}

		public String getPassword_createUser() {
			return password_createUser;
		}
		
		public String getLogin_login() {
			return login_login;
		}

		public String getPassword_login() {
			return password_login;
		}

		public String getName_Computer() {
			return name_Computer;
		}
		
		public String getIpadresse_Computer() {
			return ipadresse_Computer;
		}

		public String getDns_Computer() {
			return dns_Computer;
		}
	    
	    public HtmlDataTable getDataTable() {
	        return dataTable;
	    }

	    public UserComputer getDataItem() {
	        return dataItem;
	    }

	    public HtmlInputHidden getDataItemId() {
	        return dataItemId;
	    }

		
		public List getPers() {
			return pers;
		}

		public List getUser() {
			return user;
		}
		
		public List getComputer() {
			return computer;
		}
		
		public User getUpdateuser() {
			return updateuser;
		}
		

		public List<File> getFile() {
			synchronized (file) {
				return file;
			}
		}

	    
// Setters -----------------------------------------------------------------------------------
	    public void setIdentite(int identite) {
			this.identite = identite;
		}
	    public void setNom_createUser(String nom_createUser) {
			this.nom_createUser = nom_createUser;
		}
		public void setPrenom_createUser(String prenom_createUser) {
			this.prenom_createUser = prenom_createUser;
		}
		public void setLogin_createUser(String login_createUser) {
			this.login_createUser = login_createUser;
		}
		public void setPassword_createUser(String password_createUser) {
			this.password_createUser = password_createUser;
		}
		public void setLogin_login(String login_login) {
			this.login_login = login_login;
		}
		public void setPassword_login(String password_login) {
			this.password_login = password_login;
		}
		public void setName_Computer(String name_Computer) {
			this.name_Computer = name_Computer;
		}
		public void setIpadresse_Computer(String ipadresse_Computer) {
			this.ipadresse_Computer = ipadresse_Computer;
		}
		public void setDns_Computer(String dns_Computer) {
			this.dns_Computer = dns_Computer;
		}
	    	    
	    public void setDataTable(HtmlDataTable dataTable) {
	        this.dataTable = dataTable;
	    }

	    public void setDataItem(UserComputer dataItem) {
	        this.dataItem = dataItem;
	    }

	    public void setDataItemId(HtmlInputHidden dataItemId) {
	        this.dataItemId = dataItemId;
	
	    }

	    public void setPers(List pers) {
	    			this.pers = pers;
	    		}
	    public void setUser(List user) {
	    			this.user = user;
	    		}
	    public void setComputer(List computer) {
	    			this.computer = computer;
	    		}
	    public void setUpdateuser(User updateuser) {
	    			this.updateuser = updateuser;
	    		}
	    public void setFile(List<File> file) {
	    			this.file = file;
	    		}
	    
	    
	//------------------------------------------------------------------------------------------------------
}